package com.zhejiangzhengyuan.municipal_common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhejiangzhengyuan.municipal_common.entity.CaseInspectionEventMapping;
import com.zhejiangzhengyuan.municipal_common.entity.InspectionEvent;
import com.zhejiangzhengyuan.municipal_common.mapper.CaseInspectionEventMappingMapper;
import com.zhejiangzhengyuan.municipal_common.mapper.CaseMapper;
import com.zhejiangzhengyuan.municipal_common.mapper.InspectionEventMapper;
import com.zhejiangzhengyuan.municipal_common.service.InspectionEventService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * <p>
 * 巡检事件表，用于记录市政设施养护巡检任务中发现的事件数据 服务实现类
 * </p>
 *
 * @author linju
 * @since 2019-11-22
 */
@Service
public class InspectionEventServiceImpl extends ServiceImpl<InspectionEventMapper, InspectionEvent> implements InspectionEventService {

    @Autowired private InspectionEventMapper inspectionEventMapper;
    @Autowired private CaseMapper caseMapper;
    @Autowired private CaseInspectionEventMappingMapper caseInspectionEventMappingMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateInspectionEvent(InspectionEvent inspectionEvent) {
        inspectionEvent.setReset("是");
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("inspection_event_id",inspectionEvent.getId());
        CaseInspectionEventMapping caseInspectionEventMapping = caseInspectionEventMappingMapper.selectOne(wrapper);
        caseMapper.deleteOneWayCase(caseInspectionEventMapping.getCaseId());
        caseInspectionEventMappingMapper.deleteById(caseInspectionEventMapping.getId());
        return inspectionEventMapper.updateById(inspectionEvent);
    }
}
